<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";
import { getPaymentCollectAmount } from "@/api/admin_jsc";
const animationDuration = 3000;
 
export default {
  mixins: [resize],
  props: {
    listQuery: {
      type: Object,
    },
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "1400px",
    },
    height: {
      type: String,
      default: "300px",
    },
  },
  data() {
    return {
      showbtns: false,
      chart: null,
       xData: [],
      yData: [],
    };
  },
  mounted() {
    this.getList();
   
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
 methods: {
      getList() {
      
      getPaymentCollectAmount(this.listQuery).then((res) => {
        this.xData = res.data.data.map(function (obj, index, array) {
          var rObj = [];
          rObj = obj.week;
          return rObj;
        });
        this.yData = res.data.data.map(function (obj, index, array) {
          var rObj2 = [];

          rObj2 = obj.collectionAmount;
          return rObj2;
        });
       
        this.$nextTick(() => {
      this.initChart();
    });
      });
    },
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");

      this.chart.setOption({
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow", // 默认为直线，可选为：'line' | 'shadow'
          },
        },
        color: ["#FF89B0FF", "#FFCF5AFF", "#6EF3EDFF"],
        legend: {
          top: "-5",
          data: ["回款基准(万元)", "回款金额(万元)", "回款累积(万元)"],
        },
        grid: {
          top: 40,
          left: "2%",
          right: "2%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
              name: "周", //坐标名字
            nameLocation: "end",//坐标位置，支持start,end，middle
             type: "category",
              nameTextStyle: {//字体样式
            
            fontSize: 15,//字体大小
           
           

      },
             axisTick:{
              show:false
            },
            
               axisLine: {
               
              lineStyle: {
                color: "#616266",
              },
            },
            data: this.xData,
            axisTick: {
              alignWithLabel: false,
            },
          },
        ],
          yAxis: [
          {
            type: "value",
             axisLine: {
                show:false,
              lineStyle: {
                color: "#616266",
              },
            },
            axisTick: {
              show: false,
            },
            axisTick: {
              show: false,
            },
          },
        ],
        series: [
          {
            name: "回款基准(万元)",
            type: "line",
            symbolSize: 5,
            stack: "vistors",
             barWidth: "80px",
            label: {
              show: true,
              color: "#52A8FEFF",
            },

            data: this.yData,
            animationDuration,
          },
          {
            label: {
              show: true,
              color: "#52A8FEFF",
            },

            name: "回款金额(万元)",
            type: "line",
            symbolSize: 5,
            stack: "vistors",
             barWidth: "80px",
            data: this.yData,
            animationDuration,
          },
          {
            label: {
              show: true,
              color: "#52A8FEFF",
            },

            name: "回款累积(万元)",
            type: "line",
            symbolSize: 5,
            stack: "vistors",
             barWidth: "80px",
            data: this.yData,
            animationDuration,
          },
        ],
      });
    },
  },
};
</script>
